﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Security.Cryptography;
//using System.Text;

//namespace PlexBB.Data
//{
//    internal class PasswordTool
//    {
//        public const int PasswordSaltLength = 48; // same as in DB type (see MappingTemplate.xml)
//        private static readonly Random _random = new Random();
//        private static readonly HashAlgorithm _hashAlgorithm = SHA384.Create();

//        public static byte[] GeneratePasswordSalt()
//        {
//            byte[] passwordSalt = new byte[PasswordSaltLength];
//            _random.NextBytes(passwordSalt);
//            return passwordSalt;
//        }

//        public static bool ValidatePassword(string validatedPassword, byte[] password, byte[] passwordSalt)
//        {
//            if (password == null || passwordSalt == null)
//            {
//                return false;
//            }
//            byte[] inputBytes = ComputePasswordHash(validatedPassword, passwordSalt);
//            return Util.CompareByteArrays(inputBytes, password);
//        }

//        public static byte[] ComputePasswordHash(string password, byte[] passwordSalt)
//        {
//            if (passwordSalt == null)
//            {
//                throw new InvalidOperationException();
//            }

//            // compute the salt + password SHA1 hash and store it in _password
//            byte[] passwordBytes = Encoding.UTF8.GetBytes(password);
//            byte[] totalBytes = new byte[passwordBytes.Length + passwordSalt.Length];
//            passwordBytes.CopyTo(totalBytes, 0);
//            passwordSalt.CopyTo(totalBytes, passwordBytes.Length);
//            // thread safety?
//            return _hashAlgorithm.ComputeHash(totalBytes);
//        }
//    }
//}
